package com.drink.yan.web.rest;

import com.alibaba.fastjson.JSONObject;
import com.drink.yan.domain.YanUserDo;
import com.drink.yan.intf.entity.YanMockExams;
import com.drink.yan.intf.vo.*;
import com.drink.yan.svc.service.YanMockExamsService;
import com.drink.yan.svc.service.YanUserService;
import com.drink.yan.web.rest.req.cmd.ApplyTeacherInfoCmd;
import com.drink.yan.web.rest.req.cmd.UserDataAuthCmd;
import com.drink.yan.web.rest.req.qry.PageMockExamsQry;
import com.drink.yan.web.rest.req.qry.PageStudentQry;
import com.drink.yan.web.rest.req.qry.PageTeacherQry;
import com.meta.framework.act.entity.SysUser;
import com.meta.framework.common.core.controller.BaseController;
import com.meta.framework.common.core.page.TableResponseVo;
import com.meta.framework.common.utils.SecurityUtils;
import com.meta.framework.common.utils.poi.ExcelUtil;
import com.meta.framework.core.CommonRes;
import com.meta.framework.core.ResponseVo;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * java类简单作用描述
 *
 * @Title:
 * @Package: com.drink.yan.web.rest.app.
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2023/11/23 14:58
 * @Version: v2.0
 */
@RestController
@RequestMapping("/exams")
public class MockExamsRest extends BaseController {


    @Resource
    private YanMockExamsService yanMockExamsService;

    @Resource
    private YanUserService yanUserService;

    @ApiOperation(value = "学生模考模版导出", notes = "学生模考模版导出", tags = {"PC"})
    @GetMapping("/student/export")
    public CommonRes export(PageStudentQry qry) {
        startPage();
        if (qry.isUserAuthFilter()) {
            qry.setCurrentUserId(SecurityUtils.getUserId());
        }
        List<StudentVo> list = yanUserService.listStudent(qry);
        List<ExportStudentVo> exportStudentVos = JSONObject.parseArray(JSONObject.toJSONString(list), ExportStudentVo.class);
        ExcelUtil<ExportStudentVo> util = new ExcelUtil<>(ExportStudentVo.class);
        return util.exportExcel(exportStudentVos, "用户数据");
    }

    @ApiOperation(value = "学生模考查询", notes = "学生模考查询", tags = {"PC"})
    @GetMapping("/page")
    public TableResponseVo<List<MockExamsVo>> pageMockExams(PageMockExamsQry qry) {
       startPage();
        if (qry.isUserAuthFilter()) {
            qry.setCurrentUserId(SecurityUtils.getUserId());
        }
        List<MockExamsVo> list = yanMockExamsService.listMockExams(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "学生模考保存", notes = "学生模考保存", tags = {"PC"})
    @PostMapping("/save")
    @SneakyThrows
    public CommonRes save(@RequestBody YanMockExams yanMockExams) {
        return CommonRes.success(yanMockExamsService.saveMockExams(yanMockExams));
    }

    @ApiOperation(value = "学生模考导入", notes = "学生模考导入", tags = {"PC"})
    @PostMapping("/student/import")
    @SneakyThrows
    public CommonRes importExams(MultipartFile file, boolean updateSupport) {
        ExcelUtil<YanMockExams> util = new ExcelUtil<YanMockExams>(YanMockExams.class);
        List<YanMockExams> yanMockExams = util.importExcel(file.getInputStream());
        return CommonRes.success(yanMockExamsService.batchSave(yanMockExams, updateSupport));
    }

}
